// pages/more/more.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current: 0,
    pageWrapCount: [],
    pIndex: [],
    page:0,
    pagesize:10,
    list:[],
    keyword:"",
    keshi_two:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.getKeshi_one();
  },
  // 获取一级科室
  getKeshi_one:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/answer.keshi_arr",
      data:{
        type:'jibing'
      },
      success:function(res){
        that.setData({
          keshi_arr:res.data,
          keshi_two:res.data[0].id
        })
        that.getList(res.data[0].id,'')
      }
    })
  },
  // 获取疾病列表
  getList:function(id,keyword){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/answer.tank_list",
      data:{
        page:that.data.page,
        pagesize:that.data.pagesize,
        type:0,
        keshi_two:id,
        keyword:keyword
      },
      success:function(res){
        var page = that.data.page + 1;
        that.setData({
          list: that.data.list.concat(res.data),
          page: page
        });
      }
    })
  },
  //点击加载更多
  huoqu: function (e) {
    var that = this
    var index = e.currentTarget.dataset.index
    var current = index
    var id = e.currentTarget.dataset.id
    app.util.request({
      url: 'entry/wxapp/Yuzhen.classb',
      data: { id: id },
      'cachetime': '30',
      success: function (res) {
        console.log(res.data)
        that.setData({
          categoryfl2: res.data,
        })
        app.globalData.skuList = res.data;
        var pIndex = that.data.pIndex
        pIndex.push(current)
        console.log(pIndex, current)
        that.setData({
          pageWrapCount: that.data.pageWrapCount.concat([1]),
          current: current,
          pIndex: pIndex
        });
      }
    })
  },
  //判断是否存在
  existence: function (num, arr) {
    for (var i = 0, len = arr.length; i < len; i++) {
      if (arr[i] == num) {
        return false
      }
    }
    return true
  },
  //搜索
  searchClick: function () {
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/search/search',
    })
  },
  detailClick: function (e) {
    var id = e.currentTarget.dataset.id;
    var title = e.currentTarget.dataset.title;
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/details/details?id='+id+'&title='+title,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var keshi_two = that.data.keshi_two;
    var keyword = that.data.keyword;
    that.getList(keshi_two,keyword);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  huoqu:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    that.setData({
      keshi_two:id,
      page:0,
      list:[],
      i: e.currentTarget.dataset.index,
      current:e.currentTarget.dataset.index
    })
    var keyword = that.data.keyword
    that.getList(id,keyword)
  },
  change_keyword:function(e){
    var that = this;
    var keyword = e.detail.value;
    that.setData({
      keyword:keyword
    })
  },
  searchs:function(){
    var that = this;
    var keyword = that.data.keyword;
    var keshi_two = that.data.keshi_two;
    that.setData({
      page:0,
      list:[]
    })
    that.getList(keshi_two,keyword);
  },
  // huoqu: function (e) {
  //   var that = this

  //   this.setData({
  //     i: e.currentTarget.dataset.index
  //   })

  // },
})